﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Peekaboo2008.util;
using Peekaboo2008.model;

namespace Peekaboo2008.dao
{
    class CongNoDAO
    {
        public static DataTable CongNo_GetAll(String MaLoaiCongNo)
        {
            int i = 0;
            SqlParameter[] param = new SqlParameter[1];
            param[i] = new SqlParameter("Ma_loai_cong_no", SqlDbType.NVarChar);
            param[i++].Value = MaLoaiCongNo;
            return DataUtil.executeStore("sp_CongNo_GetAll", param);
        }
        public static DataTable LoaiCongNo_GetAll()
        {
            return DataUtil.executeStore("sp_LoaiCongNo_GetAll", null);
        }
      
        public static DataTable getCongNoByMaLoai(String Id)
        {
            int i = 0;
            SqlParameter[] param = new SqlParameter[1];
            param[i] = new SqlParameter("ID", SqlDbType.Int);
            param[i++].Value = Id;

            return DataUtil.executeStore("sp_CongNo_GetByMaLoaiCongNo", param);
        }
        public static Boolean InsertCongNo(CongNoModel _model)
        {
            SqlParameter[] param = new SqlParameter[7];
            int i = 0;
            param[i] = new SqlParameter("Ma_khach_hang", SqlDbType.Int);
            param[i++].Value = _model.Ma_khach_hang;
            param[i] = new SqlParameter("Ma_loai_cong_no", SqlDbType.Int);
            param[i++].Value = _model.Ma_loai_cong_no;
            param[i] = new SqlParameter("Thanh_toan", SqlDbType.Float);
            param[i++].Value = _model.Thanh_toan;
            param[i] = new SqlParameter("Ma_ngoai_te", SqlDbType.Int);
            param[i++].Value = _model.Ma_ngoai_te;
            param[i] = new SqlParameter("Ty_gia", SqlDbType.Float);
            param[i++].Value = _model.Ty_gia;
            param[i] = new SqlParameter("Thanh_tien", SqlDbType.Float);
            param[i++].Value = _model.Thanh_tien;           
            param[i] = new SqlParameter("Ghi_chu", SqlDbType.NVarChar);
            param[i++].Value = _model.Ghi_chu;

            return DataUtil.executeNonStore("sp_CongNo_Insert", param);
        }
        public static Boolean UpdateCongNo(CongNoModel _model)
        {
            SqlParameter[] param = new SqlParameter[8];
            int i = 0;
            param[i] = new SqlParameter("ID", SqlDbType.Int);
            param[i++].Value = _model.Id;
            param[i] = new SqlParameter("Ma_khach_hang", SqlDbType.Int);
            param[i++].Value = _model.Ma_khach_hang;
            param[i] = new SqlParameter("Ma_loai_cong_no", SqlDbType.Int);
            param[i++].Value = _model.Ma_loai_cong_no;
            param[i] = new SqlParameter("Thanh_toan", SqlDbType.Float);
            param[i++].Value = _model.Thanh_toan;
            param[i] = new SqlParameter("Ma_ngoai_te", SqlDbType.Int);
            param[i++].Value = _model.Ma_ngoai_te;
            param[i] = new SqlParameter("Ty_gia", SqlDbType.Float);
            param[i++].Value = _model.Ty_gia;
            param[i] = new SqlParameter("Thanh_tien", SqlDbType.Float);
            param[i++].Value = _model.Thanh_tien;
            param[i] = new SqlParameter("Ghi_chu", SqlDbType.NVarChar);
            param[i++].Value = _model.Ghi_chu;

            return DataUtil.executeNonStore("sp_CongNo_Update", param);
        }


        /*
         Công nợ nhà cung cấp DAO 
        */
        public static DataTable CongNo_NhaCungCap_GetAll(String MaLoaiCongNo)
        {
            int i = 0;
            SqlParameter[] param = new SqlParameter[1];
            param[i] = new SqlParameter("Ma_loai_cong_no", SqlDbType.NVarChar);
            param[i++].Value = MaLoaiCongNo;
            return DataUtil.executeStore("sp_CongNo_NhaCungCap_GetAll", param);
        }
    }
}
